import Vue from 'vue'
import Vuex from 'vuex'

import modules from "./modules";

Vue.use(Vuex)

export default function createStore() {
    return new Vuex.Store({
        state: {
            loading: false,
            userInfo: {
                name: 'wxf'
            },
            menus: [{
                title: '商家',
                key: 'business',
                children: [{
                    title: '商户管理',
                    url: '/business/list'
                }, {
                    title: '店铺管理',
                    url: '/business/shop'
                }, {
                    title: '店铺设置',
                    url: '/business/setting'
                // }, {
                //     title: '店员管理',
                //     url: '/business/clerk'
                }]
            }, {
                title: '商品',
                key: 'goods',
                children: [{
                    title: '商品管理',
                    url: '/goods/list'
                }, {
                    title: '类目管理',
                    url: '/goods/class'
                }, {
                    title: '品牌管理',
                    url: '/goods/brand'
                }, {
                    title: '属性管理',
                    url: '/goods/attr'
                }]
            }, {
                title: '用户管理',
                key: 'user',
                children: [{
                    title: '用户列表',
                    url: '/user/list'
                }]
            }, {
                title: '订单',
                key: 'order',
                children: [{
                    title: '订单管理',
                    url: '/order/list'
                }]
            }, {
                title: '促销中心',
                key: 'sales',
                children: [{
                    title: '优惠券管理',
                    url: '/sales/coupon'
                }]
            }, {
                title: '系统管理',
                key: 'system',
                children: [{
                    title: '角色管理',
                    url: '/system/role'
                }, {
                    title: '人员管理',
                    url: '/system/user'
                }]
            }]
        },
        actions: {
            setLoading: ({ commit }, loading) => {
                commit('setLoading', loading)
            }
        },
        mutations: {
            setLoading: (state, loading) => {
                state.loading = loading
            }
        },
        getters: {
            username: state => {
                return state.userInfo.name || ''
            },
            loading: state => state.loading,
            menus: state => state.menus
        },
        modules
    })
}